package com.lbloca.locate.ui.activity;

import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import androidx.appcompat.widget.Toolbar;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.gyf.immersionbar.ImmersionBar;
import com.lbloca.locate.R;
import com.lbloca.locate.biz.Config;
import com.lbloca.locate.ui.base.BaseActivity;
import com.zhy.adapter.recyclerview.CommonAdapter;
import com.zhy.adapter.recyclerview.base.ViewHolder;

import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

/**
 * 客服
 */

public class ServiceActivity extends BaseActivity {
    @BindView(R.id.id_rv_service_qq)
    RecyclerView mRvQq;
    @BindView(R.id.id_tv_mobile)
    TextView mTvMobile;
    @BindView(R.id.toolbar)
    Toolbar mToolbar;
    @BindView(R.id.id_tv_wx)
    TextView tvWx;

    private CommonAdapter mAdapter;
    private List<String> mQqList = new ArrayList<>();

    @Override
    protected void initEvents() {

    }

    @Override
    protected void initData() {

    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_service;
    }

    @Override
    protected void initView() {
        mRvQq.setLayoutManager(new GridLayoutManager(this, 2, GridLayoutManager.VERTICAL, false));

        JSONObject jsonObject = Config.SERVICES;
        if (jsonObject != null) {
            String[] qqs = jsonObject.optString("qq", "").split(",");
            for (int i = 0, length = qqs != null ? qqs.length : 0; i < length; i++) {
                mQqList.add(qqs[i]);
            }
            String wx = jsonObject.optString("wx", "");
            if (!TextUtils.isEmpty(wx)) {

                tvWx.setText(wx);
            } else{
                tvWx.setText("---");
            }
            mTvMobile.setText(jsonObject.optString("phone", ""));

        }



            mAdapter = new CommonAdapter<String>(this, R.layout.vw_service_qq_item, mQqList) {
                @Override
                protected void convert(final ViewHolder holder, final String s, final int position) {
                    holder.setText(R.id.tv_kefuQQ, s);
                }
            };
            mRvQq.setAdapter(mAdapter);

        mToolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                onBackPressed();
            }
        });
    }


    public static void start(Context context){
        Intent intent = new Intent(context,ServiceActivity.class);
        context.startActivity(intent);
    }

    @Override
    protected void initImmersionBar() {
        super.initImmersionBar();
        ImmersionBar.with(this)
                .statusBarDarkFont(true)
                .navigationBarDarkIcon(true)
                .titleBar(mToolbar)
                .init();
    }
}
